/**
 * 产品修改js
 */
var comValidform = null;
var returnStatus = false;
var cardsHistory = {
	curPage : 1,
	pageSize : 10,
	dataCache : null,

	// 设置分页
	setPageChange : function(delCurPage) {
		var url = 'mgr/userCardCtr/list';
		var params = jsUtils.serializeJson($('#searchModForm'));
		params.curPage = cardsHistory.curPage;
		params.pageSize = cardsHistory.pageSize;
		

		var cb = function(data) {
			if (data.resultCode == 200) {
				var totalCount = data.size;
				var pageTotal = (totalCount / cardsHistory.pageSize > 0) ? Math
						.ceil(totalCount / cardsHistory.pageSize) : 1;
				pageHelper.init(pageTotal, totalCount, cardsHistory.search,
						delCurPage); // 翻页事件
			}
		};
		sendApiNoLoad(url, params, cb, 'POST');
	 
	},
	
	// 查询积分规则
	search : function(pageIdx) {
		var url = 'mgr/userCardCtr/list';
		if (typeof (pageIdx) != "undefined") {
			cardsHistory.curPage = pageIdx;
		}
		
		var params = jsUtils.serializeJson($('#searchModForm'));
		params.curPage = cardsHistory.curPage;
		params.pageSize = cardsHistory.pageSize;
		
		var cb = function(data) {
			$('#tableList tbody').empty();
			var tr = '';
			if (data.resultCode == 200) {
				if (data.result != null && data.result.length > 0) {
					for (var i = 0; i < data.result.length; i++) {
						var singleObj = data.result[i];
						
						var useTimeStr = "";
						if(singleObj.useTime != null){
							 useTimeStr = getSmpFormatDateByLong(
										singleObj.useTime, true);
						}
						
						localStorage.setItem(singleObj.id + "_cardsHistory_Key",
								JSON.stringify(singleObj));

						tr += '<tr><td>'
								+ (i + 1)
								+ '</td><td>'
								+ singleObj.cardId
								+ '</td><td>'
								+  singleObj.cardTypeStr
								+ '</td><td>'
								+ singleObj.cardRate
								+ '</td><td>'
								+ singleObj.cardDesc
								+ '</td><td>'
								+ singleObj.statusStr
								+ '</td><td>'
								+ singleObj.userName
								+ '</td><td>'
								+ (singleObj.orderId != null?singleObj.orderId:"")
								+ '</td><td>'
								+ useTimeStr
								+ '</td></tr>';
					}
				} else {
					tr = '<tr><td colspan="7" style="text-align: center;color: red;">暂无数据</td></tr>';
				}
			} else {
				tr = '<tr><td colspan="7" style="text-align: center;color: red;">暂无数据</td></tr>';
			}
			$('#tableList tbody').html(tr);
			jsUtils.controlFunctionBtn();
			
		};
		sendApiNoLoad(url, params, cb, 'POST');
	},

	bindEvent : function() {
		// 查询
		$('#searchData').click(function() {
			cardsHistory.curPage = 1;
			cardsHistory.setPageChange(null);
			cardsHistory.search();
		});
	},

	init : function() {
		cardsHistory.setPageChange(null);
		cardsHistory.search();
		cardsHistory.bindEvent();
	}
}
$(document).ready(function() {
	cardsHistory.init();
});
function submitForm() {
	comValidform.submitForm();
	return returnStatus;
}